
import React, { Component } from 'react'
import {connect} from 'react-redux'

// 加载样式
import style from './index.scss'
import {showChiceAddress} from '../../actions/addAddressListActions'
//加载组件
import { Checkbox } from 'antd-mobile'

//定义
// const AgreeItem = Checkbox.AgreeItem;

// export default class CheckAndArrow extends Component {
	class CheckAndArrow extends Component {
    constructor(props) {
        super(props);
    }
    componentWillMount() {

    }

    /**
     * 事件
     */
    toUrl(url) {
	    this.context.router.push(url);
    }

    //返回的数据
    getData(data) {
         console.log(data)
        // if (data.value) {
            this.props.onClick('DOM', data.key, data.check); //传递给父组件
            //  console.log('点击Click=', data.key,data.value)
        // }
        // else {
        //      this.props.onClick('checkbox', data.target.id, data.target.checked); //传递给父组件 :手机
        // }
    }

	  deleteCertificates(event,name,id){
        this.props.onDeleteHand(event,name,id)
    }


/*
	cellNum:"13712312312"
	cityId:441900
	contactName:"最新地址"
	countyId:441901
	createTime:1503294068000
	defalutFlag:1
	fullAddr:"广东省东莞市null"
	id:"0C35C405618F4CBBA75B3B69446074D5"
	postCode:null
	provinceId:440000
	street:"分开的手机卡傅雷家书的开发萨拉的"
	streetId:null
	updateTime:1503294068000
	userId:"9678A6A590E840F3B3A558902E2A6FC9"
*/

	  toCarry(e,item){
      console.log(item)
      sessionStorage.setItem('handleItem',JSON.stringify(item))
      sessionStorage.removeItem('cacheAllState')
      console.log(item)
      let choiceAddress = {
	      cellNum: item.address.cellNum,
	      cityId: item.address.cityId ,
	      contactName: item.address.contactName,
	      countyId: item.address.countyId,
	      createTime:1503294068000,
	      defalutFlag:1,
	      fullAddr: item.address.fullAddr,
	      id: item.address.provinceId,
	      postCode:null,
	      provinceId: item.address.provinceId,
	      street: item.address.street,
	      streetId:null,
	      updateTime:'',
	      userId:""
      };
		  sessionStorage.setItem('choiceAddress', JSON.stringify(choiceAddress))  //选择的地址
		  this.props.dispatch(showChiceAddress(false))
		  sessionStorage.setItem('addressListGetIntId',1)
		  sessionStorage.removeItem('currentIndex')   //删除请求地区种类的序号，防止用户从缓存进入填写资料页，切换签注类别，再次点击返回，
		  this.toUrl('home')
		  e.stopPropagation()
    }

    /**
     * 组件
     */
    render() {

        const borderT = this.props.className ? ' ' + this.props.className : ''; //顶部有最上面一条边框的样式
        let res = this.props.data;
	    // type: state.visaType=='free'?1:state.visaType=='again'?3:state.visaType=='spouse'
	    // ?4:state.visaType=='sz'?5:null, //签注类型：1:个人游；2：团体旅游；3：商务出行；4：夫妻探亲；5:非广东户籍深圳人员个人游
      // visa: [{index: 1,check:'free',name:'往来港澳个人旅游在签注(自由行)'},{index:3,check:'again',name:'往来港澳商务再次签注'},
	    //{index:4,check:'spouse',name:'往来港澳夫妻探亲再签注'},{index:4,check:'sz',name:'在深圳非广东户籍'}],

        return (
            <div className={style.checkList}>

                {this.props.data.map((item,i)=> (

                    <div className={style.checkOption} key={item.key} onClick={(data) => this.getData(item)}>
                        <div className={style.checkInfo}>
                            <Checkbox
                                id={item.key}
                                checked={item.check}
                            >
                            </Checkbox>
                        </div>

                        <div className={style.personal}>
                            <div className={style.personalTitle} onClick={(e)=>{this.toCarry(e,item);}}>
                                <div>
                                  <span className="text-overflow-1" style={{width:'5.35rem',display: 'inline-block'}}>{item.endorseInfoObj.bizFullName}</span>
                                 </div>
                                <img src="./images/icon_to_r.png" alt=""/>
                            </div>
                            <div className={style.address}>
                                <div className={style.organizationName}>
                                  {
                                      item.endorseInfoObj.type==3?'单位组织机构名称:':item.endorseInfoObj.type==4?'配偶姓名:':''
                                  }
                                  <span>{item.endorseInfoObj.type==3?item.endorseInfoObj.orgName:item.endorseInfoObj.type==4?item.endorseInfoObj.spouseName:null}</span>

                                </div>
                                <div className={style.more}>
                                    {/*办理次数:香港,三月一次;澳门,三月一次*/}
                                  <span>签注种类:</span>
                                  {
                                      item.items.map((e,i)=>{
                                          if(e.category == 1){
	                                          return <span key={i}>香港,
                                              {
		                                            e.times == 1?'三月一次':e.times == 2?'三月二次': e.times == 3?'三月多次':
                                                e.times== 4?'一年一次': e.times == 5?'一年二次':e.times == 6?'一年多次':null
                                              }{i==0&&item.items.length>1?';':''}</span>
                                          }else {
                                            return <span key={i}> 澳门,
                                              {
	                                              e.times == 1?'三月一次':e.times == 2?'三月二次': e.times == 3?'三月多次':
                                                e.times== 4?'一年一次': e.times == 5?'一年二次':e.times == 6?'一年多次':null
                                              }</span>
                                          }
                                      })
                                  }
                                  <div className={style.dustbin} onClick={(e)=>{this.deleteCertificates(e,item.endorseInfoObj.passName,item.endorseInfoObj.passCode)}}>
	                                  <img src="./images/dustbin.png" alt="" />
                                  </div>
                                </div>
                                <div className={style.name}>收件人: <span>{item.address.contactName}</span> ，<span>{item.address.cellNum}</span></div>
                                <div className={style.location+' text-overflow-2'}>{item.address.fullAddr.replace(null,'')}{/*item.address.street*/}</div>
                            </div>
                        </div>

                    </div>
                ))}

            </div>

        );
    }
}

//使用context
CheckAndArrow.contextTypes = {
	router: React.PropTypes.object.isRequired
};
// 
CheckAndArrow.defaultProps = {
    // 需要的数据格式
    list: [
        { key: 0, label: '', check: false, value: '' },
    ]
}

function mapStateToProps(state) {
	return Object.assign({}, state.addressList,);
}

export default connect(mapStateToProps)(CheckAndArrow);
